package com.test.client.service.impl;

import com.test.client.feign.OrderService;
import com.test.client.feign.StorageService;
import com.test.client.service.ClientService;
import io.seata.spring.annotation.GlobalTransactional;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@AllArgsConstructor
public class ClientServiceImpl implements ClientService {

    private final StorageService storageService;

    private final OrderService orderService;

    @Override
    @GlobalTransactional
    public void purchase(String userId, String commodityCode, Integer orderCount) {
        storageService.deduct(commodityCode, orderCount);
        orderService.create(userId, commodityCode, orderCount);
    }
}
